import { _decorator, Component, Node, Button, director, game } from 'cc';
import { EquitmentManager } from '../EquitmentManager';
import { EventManager } from '../EventManager';
import { GameManager } from '../GameManager';
import { SaveManager } from '../SaveManager';
import { UIManager } from '../UIManager';
const { ccclass, property } = _decorator;

@ccclass('UIStart')
export class UIStart extends Component {
    @property(Button)
    public StartBtn:Button
    @property(Button)
    public ContinueBtn:Button

    start() {
        this.StartBtn.node.on(Button.EventType.CLICK, this.OnClickBtn, this);
        this.ContinueBtn.node.on(Button.EventType.CLICK, this.OnClickBtn, this);
        if (localStorage.getItem("userdata") == undefined) {
            this.ContinueBtn.node.active = false
        }
    }

    OnClickBtn(btn:Button)
    {
        let btnName = btn.node.name
        console.log(btnName)
        if (btnName == "StartBtn") {
            localStorage.removeItem("userdata")
            GameManager.instance.GameDataInit()
            director.loadScene("scene",this.OnGameSceneLoaded)
        }
        else if (btnName == "ContinueBtn") {
            SaveManager.instance.Load()
            director.loadScene("scene",this.OnGameSceneLoaded)
        }
    }

    // OnGameStart主要是用于开局获取对应的引用，禁止进行逻辑处理
    OnGameSceneLoaded()
    {
        EventManager.instance.OnGameStart()
        GameManager.instance.OnGameStart()
        UIManager.instance.OnGameStart()
        EquitmentManager.instance.OnGameStart()

        GameManager.instance.GameStart()
    }
}


